Namespace PL.TSMSDK
    Public Class TimeSheet_PL
        Inherits PLBase
        Implements IPLProcess

        Public TimeSheetCDSeq As Boolean = True

        Public Sub New()
            MyBase.New()
        End Sub

        Public Sub New(ByVal queryName As String)
            MyBase.New(queryName)
        End Sub
        ''' <summary>
        ''' Cette procedure est appellé pour chaque ligne qui sera traité.
        ''' quand le Me.MetaDataTable.Adapter.Update() est appelé
        ''' Si on veut faire de la logique sur les lignes il faut vérifier le 
        ''' DataRowState.Added, DataRowState.Modified etc...
        ''' </summary>
        ''' <param name="sender"></param>
        ''' <param name="e"></param>
        ''' <remarks></remarks>
        Sub OnRowUpdating(ByVal sender As Object, ByVal e As SqlRowUpdatingEventArgs) Handles MetaDataTable.OnRowUpdating


            'Pour le Save sur un ADD on assign la sequence
            'SSPP#..... : All String Shall recpect SQL CASING
            Me.MetaDataTable.Adapter.InsertCommand.Parameters("@TimeSheetCDSeq").Value = TimeSheetCDSeq
            Me.MetaDataTable.Adapter.UpdateCommand.Parameters("@TimeSheetCDSeq").Value = TimeSheetCDSeq




        End Sub

        Public Overrides Function Delete() As Boolean
            Throw New NotImplementedException("Delete To Come...")
            Return False
        End Function

        Public Overrides Function Validate() As Boolean
            Return Not Me.MetaDataTable.HasErrors
        End Function

        Public Overrides Sub ValidateRow(ByVal row As DataRow)
            row.ClearErrors()
            If IsDBNull(row("EmployeeID_FK")) Then
                'TODO: Get metastring ex:
                'ms = MetaString.GetMetaStringByCode("")
                row.SetColumnError("EmployeeID_FK", "Mandatory")
            End If
            '
            If row.HasErrors Then
                row.RowError = Util.GetMessage("MES-TBD") '"Please check your columns, a validation error occur"
            End If

        End Sub

        Public Shared Sub Submit(ByVal datarow As DataRow)
            datarow("DateSubmited") = Date.Today
            datarow("TimeSheetStatusID_FK") = IdRepository.APP_TIMESHEETSTATUS_SUBMITTED
        End Sub

        Public Shared Sub UnSubmit(ByVal datarow As DataRow)

            datarow("DateSubmited") = DBNull.Value
            datarow("TimeSheetStatusID_FK") = IdRepository.APP_TIMESHEETSTATUS_OPEN
            datarow("Approved") = 0
        End Sub

        Public Shared Sub Reject(ByVal datarow As DataRow)

            datarow("DateSubmited") = DBNull.Value
            datarow("TimeSheetStatusID_FK") = IdRepository.APP_TIMESHEETSTATUS_REJECTED
            datarow("Approved") = 0
        End Sub

        Public Shared Sub Reviewed(ByVal datarow As DataRow)

            datarow("TimeSheetStatusID_FK") = IdRepository.APP_TIMESHEETSTATUS_REVIEWED
        End Sub

        Public Shared Sub Approve(ByVal datarow As DataRow)

            datarow("TimeSheetStatusID_FK") = IdRepository.APP_TIMESHEETSTATUS_APPROVED
            datarow("Approved") = 1
        End Sub


        Public Function BatchRecords(dataRow() As System.Data.DataRow) As Boolean Implements IPLProcess.BatchRecords

            Return True
        End Function

        Public Function CurrentRecord(dataRow As System.Data.DataRow) As Boolean Implements IPLProcess.CurrentRecord

            Return True
        End Function

        Public Function NewRecord(dataRow As System.Data.DataRow) As Boolean Implements IPLProcess.NewRecord

            dataRow("Approved") = 0

            Return True
        End Function
    End Class
End Namespace
